//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.sunwayworld.framework.security.sso.impl;

import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.security.bean.LoginUser;
import com.sunwayworld.framework.security.bean.QrCodeLoginStatusDTO;
import com.sunwayworld.framework.security.provider.service.QrCodeLoginService;
import com.sunwayworld.framework.security.sso.SsoAuthenticator;
import com.sunwayworld.framework.utils.ServletUtils;
import com.sunwayworld.module.mdm.user.bean.CoreUserBean;
import com.sunwayworld.module.mdm.user.service.CoreUserService;
import javax.servlet.http.HttpServletRequest;

public class QrCodeLoginSsoAuthenticator implements SsoAuthenticator {

    public LoginUser authenticate() {
        HttpServletRequest request = ServletUtils.getCurrentRequest();
        String qrToken = request.getParameter("qrToken");
        QrCodeLoginService qrCodeLoginService = ApplicationContextHelper.getBean(QrCodeLoginService.class);
        QrCodeLoginStatusDTO loginStatus = qrCodeLoginService.getLoginStatus(qrToken);
        if ("2".equals(loginStatus.getStatus())) {
            CoreUserService userService = ApplicationContextHelper.getBean(CoreUserService.class);
            CoreUserBean user = userService.selectById(loginStatus.getUserId());
            LoginUser loginUser = new LoginUser(user.getId(), user.getPassword());
            loginUser.setOrgId(user.getOrgId());
            loginUser.setOrgName(user.getOrgName());
            return loginUser;
        } else {
            return null;
        }
    }
}